package com.kingdee.eas.hr.quali.handler;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;

import com.kingdee.bos.Context;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.hr.quali.JudgesLibraryInfo;
import com.kingdee.eas.hr.quali.util.QualificationUtils;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.web.handler.EditHandler;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;

public class JudgesLibraryEditHandler extends EditHandler {

	@Override
	protected void afterInitModel(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo coreBaseInfo)throws SHRWebException {
		super.afterInitModel(request, response, coreBaseInfo);
		Context ctx = SHRContext.getInstance().getContext();
		JudgesLibraryInfo info = (JudgesLibraryInfo) coreBaseInfo;
		if(info.getPerson() != null){
			String personId = String.valueOf(info.getPerson().getId());
			Map<String,Object> dataMap = QualificationUtils.getDataMap(ctx, personId);
			info.getPerson().setIdCardIssueOrg(String.valueOf(dataMap.get("quaType")));
			info.getPerson().setProtocol(String.valueOf(dataMap.get("quaLevel")));
			info.getPerson().setExtendFieldNumOne(String.valueOf(dataMap.get("quaStartDate")));
			info.getPerson().setNameShortPinYin(String.valueOf(dataMap.get("positionName")));
			info.getPerson().setNamePinYin(String.valueOf(dataMap.get("adminOrgName")));
			info.getPerson().setOldName(String.valueOf(dataMap.get("oneOrgName")));
			info.getPerson().setFullNamePingYin(String.valueOf(dataMap.get("joinDateCur")));
		}
	}
	
	@Override
	protected void afterCreateNewModel(HttpServletRequest request, HttpServletResponse response,CoreBaseInfo coreBaseInfo) throws SHRWebException {
		super.afterCreateNewModel(request, response, coreBaseInfo);
		JudgesLibraryInfo info = (JudgesLibraryInfo) coreBaseInfo;
		Context ctx = SHRContext.getInstance().getContext();
		info.setCreator(ContextUtil.getCurrentUserInfo(ctx));
		info.setLastUpdateUser(ContextUtil.getCurrentUserInfo(ctx));
		info.setCreateTime(new Timestamp(System.currentTimeMillis()));
		info.setLastUpdateTime(new Timestamp(System.currentTimeMillis()));
	}



	public String getDataInfoAction(HttpServletRequest request, HttpServletResponse response,ModelMap modelMap) throws SHRWebException {
		Context ctx = SHRContext.getInstance().getContext();
		String personId = request.getParameter("personId");
		Map<String,Object> data = new HashMap<String,Object>();
		Map<String,Object> dataMap = QualificationUtils.getDataMap(ctx, personId);
		data.put("dataMap", dataMap);
		JSONUtils.writeJson(response, data);
		return null;
	}
	
	
}
